package com.yili.oa.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yili.oa.entity.SearchBase;
import com.yili.oa.entity.TableBase;
import com.yili.oa.models.FtVip;
import com.yili.oa.service.FtVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class FtVipController {

    @Autowired
    FtVipService service;

    @RequestMapping("ftVip/get")
    @ResponseBody
    public TableBase<FtVip> get(SearchBase searchBase){
        PageHelper.startPage(searchBase.getPage(), searchBase.getLimit());
        List<FtVip> list = service.get(searchBase);
        PageInfo pageInfo = new PageInfo<>(list, searchBase.getLimit());
        TableBase<FtVip> table = new TableBase<>();
        table.setCode(0);
        table.setData(list);
        table.setMsg("");
        table.setCount(pageInfo.getTotal());
        return table;
    }

    @RequestMapping("ftVip/add")
    @ResponseBody
    public Map<String,String> add(@RequestBody FtVip ftVip) {
        Map<String, String> map = new HashMap<>();
        service.add(ftVip);
        map.put("result", "success");
        return map;
    }

    @RequestMapping("ftVip/update")
    @ResponseBody
    public Map<String,String> update(@RequestBody FtVip ftVip) {
        Map<String, String> map = new HashMap<>();
        service.update(ftVip);
        map.put("result", "success");
        return map;
    }

    @RequestMapping("ftVip/delete")
    @ResponseBody
    public Map<String,String> delete(@RequestBody List<Long> ids) {
        Map<String, String> map = new HashMap<>();
        service.delete(ids);
        map.put("result", "success");
        return map;
    }







}
